#include <cstdio>
#include <cstring>

const int max_d = 20;
int ball_switch[1 << max_d];

int main(void) {
  int kase;  
  scanf("%d", &kase);
  while (kase--) {
    int d, i;    
    while (scanf("%d %d", &d, &i) == 2) {
      memset(ball_switch, 0, sizeof(ball_switch));
      int n, m = (1 << d) - 1;
      for (int t = 0; t < i; t++) {
        n = 1;
        while (true) {
          ball_switch[n] = !ball_switch[n];
          n = ball_switch[n] ? (n * 2) : (n * 2 + 1);
          if (n > m) {
            break;
          }
        }
      }
      printf("%d\n", n / 2);
    }
  }
  
  return 0;
}
